using System.ComponentModel.DataAnnotations;
using FytSoa.Domain.Sys;
using SqlSugar;

namespace FytSoa.Domain.Crm;

/// <summary>
/// 工单
/// </summary>
[SugarTable("crm_wocorder")]
public class CrmWocOrder:Entity
{
    /// <summary>
    /// 客户编号
    /// </summary>
    [Required]
    public long CustomerId { get; set; }
        
    /// <summary>
    /// 客户信息
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(CustomerId))]
    public CrmCustomer CustomerObj { get; set; }

    /// <summary>
    /// 工单编号
    /// </summary>
    [Required]
    [StringLength(50)]
    public string Number { get; set; }

    /// <summary>
    /// 工单说明-标题
    /// </summary>
    [Required]
    [StringLength(500)]
    public string Title { get; set; }

    /// <summary>
    /// 状态（1=待接受2=处理中3=待审核4=已完成5=已关闭）
    /// </summary>
    [Required]
    public int Status { get; set; } = 1;

    /// <summary>
    /// 来源
    /// </summary>
    [Required]
    public long Source { get; set; }
    
    /// <summary>
    /// 来源
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(Source))]
    public SysCode SourceObj { get; set; }

    /// <summary>
    /// 工单类型
    /// </summary>
    [Required]
    public long Type { get; set; }
    
    /// <summary>
    /// 工单类型
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(Type))]
    public SysCode TypeObj { get; set; }

    /// <summary>
    /// 级别
    /// </summary>
    [Required]
    public long Level { get; set; }
    
    /// <summary>
    /// 级别
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(Level))]
    public SysCode LevelObj { get; set; }

    /// <summary>
    /// 标签
    /// </summary>
    [SugarColumn(IsJson = true)]
    public List<string> Tags { get; set; } = new();

    /// <summary>
    /// 处理限时
    /// </summary>
    public DateTime? TimeLimit { get; set; }

    /// <summary>
    /// 附件
    /// </summary>
    public string Files { get; set; }

    /// <summary>
    /// 派单人流程
    /// </summary>
    [Required]
    [SugarColumn(IsJson = true)]
    public List<SendUserProgress> SendUser { get; set; } = new();

    /// <summary>
    /// 关联工单列表-数组
    /// </summary>
    [SugarColumn(IsJson = true)]
    public List<RelevanceOrder> Relevance { get; set; } = new();

    /// <summary>
    /// 最后处理人
    /// </summary>
    public long LastProcessUserId { get; set; } = 0;

    /// <summary>
    /// 审核信息反馈
    /// </summary>
    [SugarColumn(IsJson = true)]
    public AuditSuccess AuditSummary { get; set; } = new();
    
    /// <summary>
    /// 驳回
    /// </summary>
    [SugarColumn(IsJson = true)]
    public RejectJson Reject { get; set; } = new ();
    
    /// <summary>
    /// 关闭原因
    /// </summary>
    [SugarColumn(IsJson = true)]
    public CloseJson CloseRemark { get; set; } = new ();

    /// <summary>
    /// 是否删除
    /// </summary>
    [Required]
    public bool IsDelete { get; set; } = false;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Required]
    public DateTime CreateTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 创建人
    /// </summary>
    public string CreateUser { get; set; }

    /// <summary>
    /// 修改时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 修改人
    /// </summary>
    public string UpdateUser { get; set; }

    /// <summary>
    /// 流转用户进度
    /// </summary>
    public class SendUserProgress
    {
        /// <summary>
        /// 用户编号
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 原因-允许为空
        /// </summary>
        public string Why { get; set; }
        
        /// <summary>
        /// 附件-允许为空
        /// </summary>
        public string Files { get; set; }

        /// <summary>
        /// 时间
        /// </summary>
        public DateTime CreateTime { get; set; }=DateTime.Now;
    }
    
    /// <summary>
    /// 关联工单详情
    /// </summary>
    public class RelevanceOrder
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public long Id { get; set; }
        
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Number { get; set; }
        
        /// <summary>
        /// 工单名称
        /// </summary>
        public string Title { get; set; }
    }
    
    /// <summary>
    /// 审核成功，需要添加附件和描述
    /// </summary>
    public class AuditSuccess
    {
        /// <summary>
        /// 文件
        /// </summary>
        public string File { get; set; }
        
        /// <summary>
        /// 备注
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime Time { get; set; } = DateTime.Now;
    }
    
    /// <summary>
    /// 驳回内容
    /// </summary>
    public class RejectJson
    {
        /// <summary>
        /// 驳回人ID
        /// </summary>
        public long Id { get; set; }
        
        /// <summary>
        /// 驳回原因
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 驳回时间
        /// </summary>
        public DateTime Time { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 关闭原因
    /// </summary>
    public class CloseJson
    {
        /// <summary>
        /// 关闭人ID
        /// </summary>
        public long Id { get; set; }
        
        /// <summary>
        /// 关闭人姓名
        /// </summary>
        public string FullName { get; set; }
        
        /// <summary>
        /// 驳回原因
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 驳回时间
        /// </summary>
        public DateTime Time { get; set; } = DateTime.Now;
    }
}